import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "@/views/Home";
import SearchPop from "@/views/search/SearchPop";

import Topic from "@/views/topic/Topic";
import Category from "@/views/category/Category";
import Cart from "@/views/cart/Cart";
import User from "@/views/user/User";
import ProductDetail from "@/components/ProductDetail";

Vue.use(VueRouter)

const routes = [
  {path: '/', redirect: '/home'},
  {
    path: '/home', component: Home, children: [
      {path: 'searchpop', name: 'searchpop', component: SearchPop}
    ], meta: {
      ifShowTabbar: true,
    },
  },
  {
    path: '/topic', component: Topic, meta: {
      ifShowTabbar: true,
    },
  },
  {
    path: '/category', component: Category, meta: {
      ifShowTabbar: true,
    },
  },
  {
    path: '/cart', component: Cart, meta: {
      ifShowTabbar: true,
    },
  },
  {
    path: '/user', component: User, meta: {
      ifShowTabbar: true,
    },
  },
  {path: '/productdetail', component: ProductDetail},
]


const router = new VueRouter({
  // mode: 'history',
  routes
})


// 路由拦截(导航守卫)


// 三个参数
/**
 * to: 代表即将进入的路由
 * from: 代表即将离开的路由
 * next: 是一个函数，每一个导航守卫必须至少搭配一个next() 帮助你跳过去你要的页面。
 */
// router.beforeEach((to,from,next) => {
//
// })


export default router
